package com.heima.behavior.controller;

import com.heima.behavior.BehaviorDto;
import com.heima.behavior.ReadBehaviorDto;
import com.heima.behavior.service.BehaviorService;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/")
@Slf4j
public class BehaviorController {

    @Autowired
    private BehaviorService behaviorService;

    /**
     * 点赞
     * @param behaviorDto 前端dto 0点赞 1取消点赞
     * @return 返回结果
     */
    @PostMapping("likes_behavior")
    public ResponseResult likesBehavior(@RequestBody BehaviorDto behaviorDto) {
        log.info("leadnews-behavior:"+ behaviorDto);
        behaviorService.likeBehavior(behaviorDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 阅读
     * @param readBehaviorDto 前端dto
     * @return 返回结果
     */
    @PostMapping("read_behavior")
    public ResponseResult readBehavior(@RequestBody ReadBehaviorDto readBehaviorDto) {
        behaviorService.readBehavior(readBehaviorDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 不喜欢
     * @param behaviorDto 前端dto
     * @return 返回结果
     */
    @PostMapping("un_likes_behavior")
    public ResponseResult unLikesBehavior(@RequestBody BehaviorDto behaviorDto){
        behaviorService.unLikesBehavior(behaviorDto);
        return ResponseResult.okResult(null);
    }


}
